package pathfinders.dijkstra;

import java.awt.Graphics;
import java.awt.*;

public class GridGraph 
{

	private static int defaultWidth = 100;
	private static int defaultHeight = 100;
	private static int defaultWeight = 10;
	
	private int graphWidth;
	private int graphHeight;
	private int edgeWeight;
	
	public Vertex[][] graph;
	
	private int numAdj = 4;
	
	public GridGraph()
	{
		graphWidth = defaultWidth;
		graphHeight = defaultHeight;
		edgeWeight = defaultWeight;
		
		
		graph = new Vertex[graphWidth][graphHeight];
		initialize(graphWidth, graphHeight, edgeWeight);
		
	}
	
	public GridGraph(int width, int height, int weight)
	{
		graphWidth = width;
		graphHeight = height;
		edgeWeight = weight;
		graph = new Vertex[width][height];
		initialize(graphWidth, graphHeight, edgeWeight);


	}
	private void initialize(int width, int height, int weight)
	{
		//System.out.println("this should only be run once");
		for(int i = 0;i < width;i++)
		{
			for(int j = 0;j < height;j++)
			{
				//System.out.println("coords : "+i+", "+j);
				graph[i][j] = new Vertex(i+","+j,numAdj,i,j); // the extra i and j are coordinates for the drawing of the tile, will probably need to be changed
				
				
				if(j > 0)
				{
					graph[i][j].adjacentVertices.add(i+","+(j-1));
				}
				// add east neighbor
				if(i < width-1)
				{
					graph[i][j].adjacentVertices.add((i+1)+","+j);
				}
				// add south neighbor
				if(j < height-1)
				{ 
					graph[i][j].adjacentVertices.add(i+","+(j+1));
				}
				// add west neighbor
				if(i > 0)
				{
					graph[i][j].adjacentVertices.add((i-1)+","+j);
				}
				
				for(int k = 0; k < numAdj;k++) graph[i][j].adjacentDistances[k] = weight;
			}
		}
	}
	
	public void printGraph()
	{
		for(int i = 0;i < graphWidth;i++)
		{
			for(int j = 0;j < graphHeight;j++)
			{
				graph[i][j].printAdjacencyList();
				System.out.println();
			}
		}	
	}
	
	public void graphEditor(String tileType, String coord)
	{
		
	}
	public void drawGraph(Graphics g)
	{
		//System.out.println("performing drawGraph");
		for(int i = 0;i < graphWidth;i++)
		{
			for(int j = 0;j<graphWidth;j++)
			{
				//if(graph[i][j].tile.getImage() == null) System.out.println(" image is null");
				//System.out.println("coords: "+graph[i][j].tile.getX()+", "+graph[i][j].tile.getY());
				g.drawImage(graph[i][j].tile.getImage(),graph[i][j].tile.getX(),graph[i][j].tile.getY(),null);
			}
		}
	}
	
}
